package cn.fl.mcr.controller;

import cmm.comm.facade.upload.api.IUploadApiService;
import cmm.comm.facade.upload.condition.SysUlFilesRecQueryCondition;
import cmm.comm.facade.upload.dto.SysUlFilesRecDTO;
import cmm.mid.core.framework.constant.tripartite.InterfaceConstants.AuditResult;
import cmm.mid.core.framework.dto.DataResultDTO;
import cmm.mid.core.framework.dto.MessageDTO;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.user.facade.system.api.IPriorityApiService;
import cmm.user.facade.system.dto.SysUsrDTO;
import cmm.user.facade.system.dto.SysUsrDatAuthRDTO;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.*;
import cn.cmm.cache.framework.utils.PropertiesCacheUtils;
import cn.fl.ass.vo.AssTrailCarChannelVO;
import cn.fl.capital.condition.CapFundVfDtlQueryCondition;
import cn.fl.capital.dto.CapFundVfDtlDTO;
import cn.fl.capital.dto.VehLoanDTO;
import cn.fl.capital.service.ICapFundSummaryService;
import cn.fl.capital.service.ICapFundVfDtlApiService;
import cn.fl.capital.service.IVehLoanInstallmentApiService;
import cn.fl.customer.service.ICstBscInfoService;
import cn.fl.customer.vo.CstBscInfoVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.inscare.transform.SysUlFilesRecVOTransform;
import cn.fl.inscare.vo.SysUlFilesRecVO;
import cn.fl.mcr.constant.McrBillMConstant;
import cn.fl.mcr.constant.UploadConstant;
import cn.fl.mcr.service.IMcrBillMService;
import cn.fl.mcr.service.IMcrWaitBuyBackService;
import cn.fl.mcr.transform.McrBillMVOTransform;
import cn.fl.mcr.transform.McrLoanAccountVOTransform;
import cn.fl.mcr.transform.McrLoanChannelVOTransform;
import cn.fl.mcr.vo.*;
import cn.fl.project.condition.PrjPrdPaySchDQueryCondition;
import cn.fl.system.constant.SysLogConstant;
import cn.fl.system.service.ISysUlFilesRecService;
import cn.lionbridgecapital.loan.model.base.Pager;
import cn.lionbridgecapital.loan.model.condition.*;
import cn.lionbridgecapital.loan.model.constant.McrCstCrLimAppConstant;
import cn.lionbridgecapital.loan.model.constant.McrCstCrLimConstant;
import cn.lionbridgecapital.loan.model.constant.McrCstCreditRecConstant;
import cn.lionbridgecapital.loan.model.dto.*;
import cn.lionbridgecapital.loan.model.utils.LoanUtils;
import cn.lionbridgecapital.loan.service.api.*;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import fl.constant.facade.framework.constant.SystemConstant;
import fl.customer.facade.customer.api.ICustomerApiService;
import fl.customer.facade.customer.api.ICustomerQueryApiService;
import fl.customer.facade.customer.dto.CstBscInfoDTO;
import fl.customer.facade.customer.dto.CstNpBscInfoDTO;
import fl.yntrust.facade.api.IYnTrustApi;
import fl.yntrust.facade.dto.CapOverdueDtlDTO;
import fl.yntrust.facade.dto.RepurchaseDTO;
import fl.yntrust.facade.dto.RepurchaseDetail;
import fl.yntrust.facade.dto.UploadFilesManageDTO;
import net.sf.json.JSONArray;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import pam.wkxt.facade.api.IWkxtApiService;
import pam.wkxt.facade.dto.PrepaymentDTO;
import pay.business.facade.custpay.api.ICmmInstallmentApiService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.*;

/**
 * @Description: 小贷账单主表 控制层
 */
@Controller
@RequestMapping("/mcr/mcrApproval")
public class McrApprovalController extends BaseController {
    private static final Logger logger = LoggerFactory.getLogger(McrApprovalController.class);

    /**
     * McrBillM 服务层BEAN
     */
    @Autowired
    private IMcrBillMService mcrBillMService;
    @Autowired
    private IMcrBillMApiService publicMcrBillMApiService ;
    @Autowired
    private ICapFundSummaryService capFundSummaryService;
    @Autowired
    private IMcrBillDApiService publicMcrBillDApiService;
    @Autowired
    private IMcrInformTransferApiService publicMcrInformTransferApiService;
    @Autowired
    private ICapFundVfDtlApiService capFundVfDtlApiService;

    /**
     * 附件服务
     */
    @Autowired
    private ISysUlFilesRecService sysUlFilesRecService;

    @Autowired
    private IMcrLoanAccountApiService publicMcrLoanAccountApiService;
    @Autowired
    private IMcrLoanChannelApiService publicMcrLoanChannelApiService;
    @Autowired
	private IYnTrustApi ynTrustApi;
    @Autowired
    private ICstBscInfoService cstBscInfoService;
    @Autowired
    private IPriorityApiService priorityApiService;
    @Autowired
    private IMcrCstCrLimApiService publicMcrCstCrLimApiService;
    @Autowired
    private IWkxtApiService wkxtApiService;
    @Autowired
    private IMcrWaitBuyBackService mcrWaitBuyBackService;
    @Autowired
    private IMcrLoanRecApiService publicMcrLoanRecApiService;
    @Autowired
    private ICmmInstallmentApiService cmmInstallmentApiService;
    @Autowired
    private IVehLoanInstallmentApiService vehLoanInstallmentApiService;
    @Autowired
    private IMcrBillBuyBackRecordApiService mcrBillBuyBackRecordApiService;
    @Autowired
    private ICustomerQueryApiService customerQueryApiService;
    @Autowired
    private IUploadApiService uploadApiService;
    @Autowired
    private ICustomerApiService customerApiService;

    /**
     * 到列表页面
     */
    @RequestMapping(value = "/toListPage.do", method = {RequestMethod.GET})
    public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "toListPage", "加载McrBillM列表页面.", CurrentThreadContext.getCurrentUserName());
        ModelAndView mav = new ModelAndView("mcr/mcrApproval/mcrApprovalList");

        //查询数据字典
        List<KeyValueVO> loanBizTypCdList = this.mcrBillMService.searchCdList(McrBillMConstant.SYS_DIC_LOAN_BIZ_TYP_CD);
        List<KeyValueVO> crTypCdList = this.mcrBillMService.searchCdList(McrBillMConstant.SYS_DIC_CR_TYP_CD);
        List<KeyValueVO> loanStsCdList = this.mcrBillMService.searchCdList(McrBillMConstant.SYS_DIC_LOAN_STS_CD);
        //业务类型
        mav.addObject("loanBizTypCdList", JSON.toJSONString(loanBizTypCdList));
        //贷款类型
        mav.addObject("crTypCdList", JSON.toJSONString(crTypCdList));
        //贷款状态
        mav.addObject("loanStsCdList", JSON.toJSONString(loanStsCdList));

        //资方渠道
        McrLoanChannelQC channelQc = new McrLoanChannelQC();
        List<McrLoanChannelVO> channelList = McrLoanChannelVOTransform.toVOList(publicMcrLoanChannelApiService.searchMcrLoanChannelDTOList(channelQc));
        mav.addObject("channelList", channelList);
        //资方账户
        McrLoanAccountQC accountQc = new McrLoanAccountQC();
        List<McrLoanAccountVO> accountList = McrLoanAccountVOTransform.toVOList(publicMcrLoanAccountApiService.searchMcrLoanAccountDTOList(accountQc));
        mav.addObject("accountList", accountList);

        return mav;
    }


    /**
     * 初始化列表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/initList.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object initMcrBillMList(HttpServletRequest request, HttpServletResponse response) {
        String currentPage = request.getParameter("page");
        String pageSize = request.getParameter("pagesize");
        Pager page = new Pager();
        if (StringUtils.isNotEmpty(currentPage)) {
            page.setCurrentPage(Integer.parseInt(currentPage));
        }

        if (StringUtils.isNotEmpty(pageSize)) {
            page.setEveryPage(Integer.parseInt(pageSize));
        }

        McrBillMQC qc = new McrBillMQC();
        //设置查询条件？
        String cstNm = request.getParameter("cstNm");
        if (StringUtils.isNotBlank(cstNm)) {
            qc.setCstNm(cstNm);
        }
        String cstId = request.getParameter("cstId");
        if (StringUtils.isNotBlank(cstId)) {
            qc.setCstId(Long.valueOf(cstId));
        }
        String crCntNo = request.getParameter("crCntNo");
        if(StringUtils.isNotBlank(crCntNo)){
            qc.setCrCntNo(crCntNo);
        }
        String loanBizTypCd = request.getParameter("loanBizTypCd");
        if(StringUtils.isNotBlank(loanBizTypCd)){
            qc.setLoanBizTypCd(loanBizTypCd);
        }
        String loanStsCd = request.getParameter("loanStsCd");
        if(StringUtils.isNotBlank(loanStsCd)){
            qc.setLoanStsCd(loanStsCd);
        }
        String crTypCd = request.getParameter("crTypCd");
        if(StringUtils.isNotBlank(crTypCd)){
            qc.setCrTypCd(crTypCd);
        }
        String loanId = request.getParameter("loanId");
        String accountId = request.getParameter("accountId");
        if(StringUtils.isNotEmpty(loanId)){
        	qc.setLoanId(Long.parseLong(loanId));
        }
        if(StringUtils.isNotEmpty(accountId)){
        	 qc.setLoanAccountId(Long.parseLong(accountId));
        }
        String isInform = request.getParameter("isInform");
        if(StringUtils.isNotEmpty(isInform)){
            qc.setIsInform(Integer.parseInt(isInform));
        }
        qc.setOpUsrId(CurrentThreadContext.getCurrentUserId());
        String cstTypeCd = request.getParameter("cstTypeCd");
        if(StringUtils.isNotEmpty(cstTypeCd)){
            if(cstTypeCd.equals("0")){
                List<String> cstTypes = new ArrayList<String>();
                cstTypes.add("0");
                cstTypes.add("3");
                qc.setCstTypeCdList(cstTypes);
                qc.setOrgCdType("1");
            }else{
                qc.setCstTypCd(cstTypeCd);
            }
        }
        String cstTypeCdList = request.getParameter("cstTypeCdList");
        BaseLogUtils.info(logger,"initMcrBillMList","初始化McrBillM列表页面数据.外部小贷请求参数.cstTypeCdList:"+cstTypeCdList);
        if(StringUtils.isNotEmpty(cstTypeCdList)){
            String[] split = cstTypeCdList.split(",");
            List<String> strings = Arrays.asList(split);
            qc.setCstTypeCdList(strings);
        }

        String remarkCode = request.getParameter("remarkCode");
        if(StringUtils.isNotEmpty(remarkCode)){
            qc.setRemarkCode(remarkCode);
        }
        qc.setIsDel(BaseConstant.IS_YESNO_NO);
        page.setCondition(qc);

        BaseLogUtils.info(logger, "initMcrBillMList", "初始化McrBillM列表页面数据.DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
        Pager pager = this.mcrBillMService.searchListPage(page);
        List<McrBillMVO> list = (List<McrBillMVO>) pager.getResultList();
        if(CollectionUtils.isNotEmpty(list)){
        	for(McrBillMVO vo : list){
        		if(vo.getLoanAccountId()!=null){
        			McrLoanAccountDTO mcrLoanAccountDTO = this.publicMcrLoanAccountApiService.selectMcrLoanAccountDTOById(vo.getLoanAccountId());
        			vo.setAccountName(mcrLoanAccountDTO.getAccountName());
        		}
                CstBscInfoDTO cstBscInfoDTO = this.customerQueryApiService.getCstBscInfoById(vo.getCstId());//基本信息
                CstNpBscInfoDTO cstNpBscInfoDTO = this.customerQueryApiService.getCstNpBscInfoById(vo.getCstId());//基本信息
                vo.setCertNo(cstBscInfoDTO.getCertNo());
                //vo.setRefMp(usrList.get(0).getUsrNm().replaceAll("(\\d{3})\\d{4}(\\d{4})","$1****$2"));
                vo.setRefMp(cstNpBscInfoDTO.getMp1());
                vo.setCustName(cstBscInfoDTO.getCstNm());
            }
        }
        ListPageVO<McrBillMVO> listPage = new ListPageVO<McrBillMVO>(list, pager.getTotalCount());
        return listPage;
    }

    /**
     * 得到一条记录
     *
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getById.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object getMcrBillMById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        String id = request.getParameter("id");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
        if (StringUtils.isEmpty(id)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.info(logger, "getMcrBillMById", "获取McrBillM数据,主键参数为空.", CurrentThreadContext.getCurrentUserName());
            return result;
        }

        try {
            McrBillMVO vo = this.mcrBillMService.selectById(Long.valueOf(id));
            if (null == vo) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
                BaseLogUtils.info(logger, "getMcrBillMById", "获取McrBillM数据不存在,ID:" + id, CurrentThreadContext.getCurrentUserName());
            }
            result.setData(vo);
            BaseLogUtils.info(logger, "getMcrBillMById", "获取McrBillM数据成功,ID:" + id, CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.info(logger, "getMcrBillMById", "获取McrBillM数据失败,ID:" + id + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "getMcrBillMById", "获取McrBillM数据失败,系统错误.ID:" + id + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return result;
    }


    /**
     * 三方机构转我司 重置属性
     * @param mcrBillMDTO
     * @return
     * @throws BaseException
     */
    private McrBillMDTO reSetMcrBillMDTO(McrBillMDTO mcrBillMDTO) throws BaseException{
        mcrBillMDTO.setLoanSource(McrBillMConstant.LOAN_SOURCE_0);
        mcrBillMDTO.setLoanId(null);
        mcrBillMDTO.setLoanName(null);
        mcrBillMDTO.setLoanChannel(null);
        mcrBillMDTO.setLoanAccountId(null);
        mcrBillMDTO.setLoanAccountNm(null);
        mcrBillMDTO.setIsInform(1);
        int count = this.publicMcrBillMApiService.reSetMcrBillMDTO(mcrBillMDTO);
        BaseLogUtils.info(logger, "reSetMcrBillMDTO", "三方机构转我司.重置属性结果：" + count + "-账单：" + mcrBillMDTO.getId());
        return mcrBillMDTO;
    }


    /**
     * 人工处理放款结果
     */
    @RequestMapping(value = "/editLoanStsCdType.do", method = { RequestMethod.POST })
    @ResponseBody
    public Object editLoanStsCdType(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "editLoanStsCdType", "人工处理放款结果新.开始时间["+startTm+"]");
        String id = request.getParameter("id");
        String cstTypCd = request.getParameter("cstTypCd");
        String loanStsCd = request.getParameter("loanStsCd");
        BaseLogUtils.info(logger, "editLoanStsCdType", "人工处理放款结果新,参数.[id="+id+"]"+"[cstTypCd="+cstTypCd+"]"+"[loanStsCd="+loanStsCd+"]", CurrentThreadContext.getCurrentUserName());
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_UPDATE_SUCC);
        if(StringUtils.isEmpty(id) || StringUtils.isEmpty(cstTypCd) || StringUtils.isEmpty(loanStsCd)){
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.info(logger, "editLoanStsCdType", "人工处理放款结果新,参数不全.[id="+id+"]"+"[cstTypCd="+cstTypCd+"]"+"[loanStsCd="+loanStsCd+"]", CurrentThreadContext.getCurrentUserName());
            return result;
        }
        try {
            McrBillMDTO dto = new McrBillMDTO();
            dto.setId(Long.valueOf(id));
            dto.setLoanStsCd(loanStsCd);
            dto.setCstTypCd(cstTypCd);
            dto.setUsrNm(CurrentThreadContext.getCurrentUserName());
            DataResultDTO dataResultDTO = this.publicMcrCstCrLimApiService.manLoanProcessingLgs(dto);
            if(dataResultDTO ==null || dataResultDTO.getSuccess() == BaseConstant.IS_YESNO_NO){
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(dataResultDTO.getInfo());
                BaseLogUtils.info(logger, "editLoanStsCdType", "人工处理放款结果新失败.[id="+id+"] DATA:" + JSONObject.toJSONString(dataResultDTO), CurrentThreadContext.getCurrentUserName());
                return result;
            }
            BaseLogUtils.info(logger, "editLoanStsCdType", "人工处理放款结果新成功.[id="+id+"] DATA:" + JSONObject.toJSONString(dataResultDTO), CurrentThreadContext.getCurrentUserName());
        }catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "editLoanStsCdType", "人工处理放款结果新失败.[id="+id+"]"  + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.info(logger, "editLoanStsCdType", "人工处理放款结果新失败.[id="+id+"]" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return result;
    }

    /**
     * 领取记录
     */
    @RequestMapping(value = "/claim.do")
    @ResponseBody
    public Object claim(HttpServletRequest request, HttpServletResponse response, McrBillMDTO entity) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
        try {
            if(entity == null || entity.getId() == null){
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo("领取记录失败，ID不能为空");
                return result;
            }
            entity.setClaim(CurrentThreadContext.getCurrentUserId().toString());
            entity.setAuditVisitStatus(McrCstCreditRecConstant.STATUS1);
            boolean success = this.publicMcrBillMApiService.modifyMcrBillM(entity);
            if(!success){
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
                BaseLogUtils.info(logger, "modify", "领取记录失败.[ID="+entity.getId()+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
            }
            BaseLogUtils.info(logger, "modify", "领取记录成功.[ID="+entity.getId()+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
        }catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "modify", "领取记录失败.[ID="+entity.getId()+"] DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "modify", "领取记录失败.[ID="+entity.getId()+"] DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return result;
    }


    /**
     * 到新增/修改页面-回访信息(客户小贷授信记录)
     */
    @RequestMapping(value = "/toAddmcrCstCreditRecPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toAddmcrCstCreditRecPage(HttpServletRequest request, HttpServletResponse response) {
        String projectId = request.getParameter("projectId");//项目ID
        String carId = request.getParameter("carId");//车辆ID
        String usrId = request.getParameter("usrId");//用户ID
        String isDetail = request.getParameter("isDetail");//是否详情标识(1:详情页面不可编辑,操作按钮隐藏)
        ModelAndView view = new ModelAndView("audit/audReturnVisit/audReturnVisitRecAdd");
        try {

            // 获取行驶证图片信息
            SysUlFilesRecQueryCondition sysUlFilesRecQueryCondition = new SysUlFilesRecQueryCondition();
            sysUlFilesRecQueryCondition.setPkId(carId);
            sysUlFilesRecQueryCondition.setCfgCd(PropertiesCacheUtils.getProperty(UploadConstant.CFG_INS_VEH_LIC_CD));
            sysUlFilesRecQueryCondition.setOrgCd(PropertiesCacheUtils.getProperty(SystemConstant.INS_USE_ORG_CD));
            sysUlFilesRecQueryCondition.setSysCd(PropertiesCacheUtils.getProperty(SystemConstant.INS_SERVICE_CD));
            BaseLogUtils.info(logger, "toAddmcrCstCreditRecPage", "信审回访.配置文件：" + JSON.toJSONString(sysUlFilesRecQueryCondition));
            List<SysUlFilesRecVO> listFilesVo = SysUlFilesRecVOTransform.toVOList(this.uploadApiService.searchSysUlFilesRecNoUrlPrefixList(sysUlFilesRecQueryCondition));
            BaseLogUtils.info(logger, "toAddmcrCstCreditRecPage", "信审回访.行驶证信息：" + JSON.toJSONString(listFilesVo));
            if (CollectionUtils.isNotEmpty(listFilesVo)) {
                String servicePath = PropertiesCacheUtils.getProperty(UploadConstant.UPLOAD_SERVER_PATH);
                for (SysUlFilesRecVO sysUlFilesRecVo : listFilesVo) {
                    if (PropertiesCacheUtils.getProperty(UploadConstant.CFG_DTL_VEH_LIC_10).equals(sysUlFilesRecVo.getCfgDtlCd())) {
                        view.addObject("driFirPho", servicePath + sysUlFilesRecVo.getFilePath());
                    } else if (PropertiesCacheUtils.getProperty(UploadConstant.CFG_DTL_VEH_LIC_20).equals(sysUlFilesRecVo.getCfgDtlCd())) {
                        view.addObject("driSecPho", servicePath + sysUlFilesRecVo.getFilePath());
                    }
                }
            }

            // 获取照片信息
            this.getParamPhoto(view,usrId);

        } catch (Exception e) {
            e.printStackTrace();
            BaseLogUtils.error(logger, "toAddmcrCstCreditRecPage", "toAddmcrCstCreditRecPage错误信息："+e.getMessage());
        }
        BaseLogUtils.info(logger, "toAddPage", "跳转到修改页面.[projectId=" + projectId + "]", CurrentThreadContext.getCurrentUserName());
        return view;
    }

    /**
     * 获取图片信息(信审回访)
     * @param view
     * @return
     */
    private ModelAndView getParamPhoto(ModelAndView view,String usrId){
        if (StringUtils.isEmpty(usrId)){
            BaseLogUtils.info(logger, "getParamPhoto", "获取图片信息(信审回访).用户信息为空");
            return view;
        }

        try{

            // 获取身份证信息
            BaseLogUtils.info(logger, "getParamPhoto", "获取图片信息(信审回访).开始获取身份证图片.usrId:"+usrId);
            List<SysUlFilesRecDTO> sysUlFileCertList = this.getSysUlFileCertList(usrId);
            if (CollectionUtils.isNotEmpty(sysUlFileCertList)){
                String servicePath = PropertiesCacheUtils.getProperty(UploadConstant.UPLOAD_SERVER_PATH);
                for (SysUlFilesRecDTO sysUlFilesRecDTO : sysUlFileCertList) {
                    // 身份证正面  10  用户ID
                    if (McrCstCrLimAppConstant.CODE_CD_CERTIFI001.equals(sysUlFilesRecDTO.getCfgCd()) && McrCstCrLimAppConstant.ID_CARD_DTL_10.equals(sysUlFilesRecDTO.getCfgDtlCd())){
                        BaseLogUtils.info(logger, "getParamPhoto", "获取图片信息(信审回访).身份证正面图片获取成功.usrId:"+usrId+",path:"+sysUlFilesRecDTO.getFilePath());
                        view.addObject("certUlFileFront",sysUlFilesRecDTO.getFilePath());
                        view.addObject("certFrontUlFileName",sysUlFilesRecDTO.getFileNm());
                    }
                    // 身份证反面  20  用户ID
                    if (McrCstCrLimAppConstant.CODE_CD_CERTIFI001.equals(sysUlFilesRecDTO.getCfgCd()) && McrCstCrLimAppConstant.ID_CARD_DTL_BACK_20.equals(sysUlFilesRecDTO.getCfgDtlCd())){
                        BaseLogUtils.info(logger, "getParamPhoto", "获取图片信息(信审回访).身份证反面图片获取成功.usrId:"+usrId+",path:"+sysUlFilesRecDTO.getFilePath());
                        view.addObject("certUlFileBack",sysUlFilesRecDTO.getFilePath());
                        view.addObject("certBackUlFileName",sysUlFilesRecDTO.getFileNm());
                    }
                    // 身份证正面  10  客户ID
                    if (McrCstCrLimAppConstant.CODE_CD_CST004.equals(sysUlFilesRecDTO.getCfgCd()) && McrCstCrLimAppConstant.ID_CARD_DTL_10.equals(sysUlFilesRecDTO.getCfgDtlCd())){
                        BaseLogUtils.info(logger, "getParamPhoto", "获取图片信息(信审回访).身份证正面图片获取成功.cstId:"+sysUlFilesRecDTO.getPkId()+",path:"+sysUlFilesRecDTO.getFilePath());
                        view.addObject("certUlFileFront",sysUlFilesRecDTO.getFilePath());
                        view.addObject("certFrontUlFileName",sysUlFilesRecDTO.getFileNm());
                    }
                    // 身份证反面  20  客户ID
                    if (McrCstCrLimAppConstant.CODE_CD_CST004.equals(sysUlFilesRecDTO.getCfgCd()) && McrCstCrLimAppConstant.ID_CARD_DTL_BACK_11.equals(sysUlFilesRecDTO.getCfgDtlCd())){
                        BaseLogUtils.info(logger, "getParamPhoto", "获取图片信息(信审回访).身份证反面图片获取成功.cstId:"+sysUlFilesRecDTO.getPkId()+",path:"+sysUlFilesRecDTO.getFilePath());
                        view.addObject("certUlFileBack",sysUlFilesRecDTO.getFilePath());
                        view.addObject("certBackUlFileName",sysUlFilesRecDTO.getFileNm());
                    }
                }
            }
        }catch (BaseException ex){
            BaseLogUtils.error(logger,"getParamPhoto","获取图片信息(信审回访).异常.ex:"+ex.getMessage(),ex);
        }catch (Exception ex){
            BaseLogUtils.error(logger,"getParamPhoto","获取图片信息(信审回访).异常.ex:"+ex.getMessage(),ex);
        }
        return view;
    }

    /**
     * 获取身份证附件信息
     * @param usrId
     * @return
     */
    private List<SysUlFilesRecDTO> getSysUlFileCertList(String usrId){
        BaseLogUtils.info(logger, "getSysUlFileCertList", "获取身份证信息.开始获取身份证图片信息.usrId:"+usrId);
        List<SysUlFilesRecDTO> sysUlFilesRecDTOS = new ArrayList<>();
        try{
            // 根据用户ID获取用户信息
            SysUlFilesRecQueryCondition queryCondition = new SysUlFilesRecQueryCondition();
            queryCondition.setSysCd(PropertiesCacheUtils.getProperty(SystemConstant.FL_SERVICE_CD));
            queryCondition.setPkId(usrId);
            queryCondition.setCfgCd(McrCstCrLimAppConstant.CODE_CD_CERTIFI001);
            BaseLogUtils.info(logger, "getSysUlFileCertList", "获取身份证信息.根据用户ID查询身份证参数.param:"+JSONObject.toJSONString(queryCondition));
            sysUlFilesRecDTOS = this.uploadApiService.searchSysUlFilesRecList(queryCondition);

            // 查询客户ID 根据客户ID查询证件附件
            if (CollectionUtils.isEmpty(sysUlFilesRecDTOS)){
                BaseLogUtils.info(logger, "getSysUlFileCertList", "获取身份证信息.开始查询客户ID.usrId:"+usrId);
                List<CstBscInfoDTO> cstBscInfoDTOS = this.customerApiService.searchListByUsrId(Long.valueOf(usrId));
                if (CollectionUtils.isEmpty(cstBscInfoDTOS)){
                    BaseLogUtils.info(logger, "getSysUlFileCertList", "获取身份证信息.未获取到客户信息.usrId:"+usrId);
                    return sysUlFilesRecDTOS;
                }

                // 根据客户ID获取证件附件信息
                CstBscInfoDTO cstBscInfoDTO = cstBscInfoDTOS.get(0);
                queryCondition.setPkId(String.valueOf(cstBscInfoDTO.getId()));
                queryCondition.setCfgCd(McrCstCrLimAppConstant.CODE_CD_CST004);
                BaseLogUtils.info(logger, "getSysUlFileCertList", "获取身份证信息.根据客户ID查询身份证.param:"+JSONObject.toJSONString(queryCondition));
                sysUlFilesRecDTOS = this.uploadApiService.searchSysUlFilesRecList(queryCondition);
            }

        }catch (BaseException ex){
            BaseLogUtils.error(logger,"getSysUlFileCertList","获取身份证信息异常.异常.ex:"+ex.getMessage(),ex);
            throw new BaseException(BaseExceptionConstant.COMMON_0002,ex.getMessage());
        }catch (Exception ex){
            BaseLogUtils.error(logger,"getSysUlFileCertList","获取身份证信息异常.异常.ex:"+ex.getMessage(),ex);
            throw new BaseException(BaseExceptionConstant.COMMON_0002,ex.getMessage());
        }
        BaseLogUtils.info(logger, "getSysUlFileCertList", "获取身份证信息.获取身份证图片信息结果.usrId:"+usrId+",param:"+JSONObject.toJSONString(sysUlFilesRecDTOS));
        return sysUlFilesRecDTOS;
    }
}

